﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using vnCommon;
using vnFingerPrint.BusinessObject;

namespace vnFingerPrint.DataAccess
{
    public class Permission_DataAccess
    {
        public static List<Permission_Object> SelectAll()
        {
            string SelectQuery = @"Select * from [Permission]";
            List<Permission_Object> result = new List<Permission_Object>();
            DataTable tb = commonDatabase.GetSQLDataTable(clsConnectionString.GetConnectionString(), SelectQuery);
            foreach (DataRow row in tb.Rows)
            {
                Permission_Object newObject = new Permission_Object();
                newObject.Id = int.Parse(row["Id"].ToString());
                newObject.Name = (string)row["Name"];
                newObject.Role = row["Role"].ToString();
                result.Add(newObject);
            }
            return result;
        }
        public static Permission_Object Find(int Id)
        {
            string SelectQuery = @"Select * from [Permission] where Id=@Id";
            List<SqlParameter> sps = new List<SqlParameter>();
            sps.Add(new SqlParameter("Id",Id));
            Permission_Object result = new Permission_Object();
            DataTable tb = commonDatabase.GetSQLDataTable(clsConnectionString.GetConnectionString(), SelectQuery,sps);
            if (tb.Rows.Count>0)
            {
                result.Id = int.Parse(tb.Rows[0]["Id"].ToString());
                result.Name = tb.Rows[0]["Name"].ToString();
                result.Role = tb.Rows[0]["Role"].ToString();
            }
            return result;
        }
    }
}
